package com.it.schoolbookshop_back.service.impl;

import com.it.schoolbookshop_back.entities.po.Report;
import com.it.schoolbookshop_back.mapper.ReportMapper;
import com.it.schoolbookshop_back.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 举报服务实现类
 */
@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    
    @Autowired
    private ReportMapper reportMapper;
    
    @Override
    public List<Report> getReportsByReporterId(Integer reporterId) {
        log.info("获取用户ID{}的举报记录", reporterId);
        return reportMapper.selectByReporterId(reporterId);
    }
    
    @Override
    public List<Report> getReportsByReportedId(Integer reportedId) {
        log.info("获取被举报用户ID{}的举报记录", reportedId);
        return reportMapper.getReportsByReportedId(reportedId);
    }
    
    @Override
    public List<Report> getReportsByBookId(Integer bookId) {
        log.info("获取书籍ID{}的举报记录", bookId);
        return reportMapper.getReportsByBookId(bookId);
    }
    
    @Override
    public boolean createReport(Report report) {
        log.info("创建举报：{}", report);
        try {
            return reportMapper.insert(report) > 0;
        } catch (Exception e) {
            log.error("创建举报失败：{}", e.getMessage(), e);
            return false;
        }
    }
    
    @Override
    public boolean processReport(Integer reportId, String status, String adminComment) {
        log.info("处理举报ID{}，状态：{}，备注：{}", reportId, status, adminComment);
        try {
            int result = reportMapper.updateReportStatus(reportId, status, adminComment);
            return result > 0;
        } catch (Exception e) {
            log.error("处理举报失败：{}", e.getMessage(), e);
            return false;
        }
    }
    
    @Override
    public List<Report> getAllReports() {
        log.info("获取所有举报记录");
        return reportMapper.getAllReports();
    }
} 